package com.loren.oauth.web.controller;

import com.loren.oauth.social.SocialAuthenticationToken;
import lombok.AllArgsConstructor;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor
@RequestMapping("/test")
public class TestController {

    private final AuthenticationManager authenticationManager;

    @GetMapping("/social")
    public Object testSocialLogin() {

        SocialAuthenticationToken socialAuthenticationToken = new SocialAuthenticationToken("Social_OpenId");

        Authentication authenticate = this.authenticationManager.authenticate(socialAuthenticationToken);

        SecurityContextHolder.getContext().setAuthentication(authenticate);

        return null;
    }

}
